package cn.xjfcloud.onedriveserver.handler;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
	
	private static final Logger LOG = LoggerFactory.getLogger(GlobalExceptionHandler.class);
	
	@ExceptionHandler(value = {Exception.class})
	@ResponseStatus(code = HttpStatus.OK)
	public Map<String, Object> handleGlobalException(Exception ex){
		Map<String, Object> map = new HashMap<String, Object>();
		LOG.error("全局错误:", ex);
		map.put("code", "500");
		map.put("err", ex.getMessage());
		return map;
	}
}
